const assert = require("assert");

const Eva = require("./Eva");

const eva = new Eva();

// evaParser.js 通过 npm run parse-output 生成
const evaParser = require("./evaParser");

function testFnGlobl(eva, code, expected) {
  const exp = evaParser.parse(`(begin ${code})`);
  assert.strictEqual(eva.evalGlobal(exp), expected);
}
testFnGlobl(
  eva,
  `
  (class Point null
    (begin
      (def constructor (this x y)
        (begin
          (set (prop this x) x)
          (set (prop this y) y)))
      (def calc (this)
        (+ (prop this x) (prop this y)))))
  (var p (new Point 10 20))
  ((prop p calc) p)
`,
  30
);

testFnGlobl(
  eva,
  `
  (class Point3D Point
    (begin
      (def constructor (this x y z)
      (begin
        ((prop (super Point3D) constructor) this x y)
        (set (prop this z) z)))
      (def calc (this)
        (+ ((prop (super Point3D) calc) this)
            (prop this z)))))
    (var p3 (new Point3D 10 20 30))
    ((prop p3 calc) p3)
`,
  60
);

console.log();
console.log("All assertions parssed!!!");
